package com.rev;

// Generated 18 mai 2013 20:44:38 by Hibernate Tools 3.4.0.CR1

import com.util.HibernateUtil;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Example;

/**
 * Home object for domain model class Source.
 * @see com.rev.Source
 * @author Hibernate Tools
 */
public class SourceHome {

	private static final Log log = LogFactory.getLog(SourceHome.class);

	private final SessionFactory sessionFactory = getSessionFactory();

	protected SessionFactory getSessionFactory() {
		try {
			return HibernateUtil.getSessionFactory();
		} catch (Exception e) {
			log.error("Could not locate SessionFactory in JNDI", e);
			throw new IllegalStateException(
					"Could not locate SessionFactory in JNDI");
		}
	}

	public void persist(Source transientInstance) {
		log.debug("persisting Source instance");
		try {
			HibernateUtil.getSession().persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(Source instance) {
		log.debug("attaching dirty Source instance");
		try {
			HibernateUtil.getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Source instance) {
		log.debug("attaching clean Source instance");
		try {
			HibernateUtil.getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(Source persistentInstance) {
		log.debug("deleting Source instance");
		try {
			HibernateUtil.getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Source merge(Source detachedInstance) {
		log.debug("merging Source instance");
		try {
			Source result = (Source) HibernateUtil.getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public Source findById(int id) {
		log.debug("getting Source instance with id: " + id);
		try {
			Source instance = (Source) HibernateUtil.getSession().get(
					"com.rev.Source", id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Source instance) {
		log.debug("finding Source instance by example");
		try {
			List results = HibernateUtil.getSession()
					.createCriteria(Source.class)
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
}
